<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <button @click="fn(-1)">count--</button>
      <p>count: {{ count }}</p>
      <button @click="fn(1)">count++</button>
      <p>doubleCount: {{ doubleCount }}</p>

      <hr />

      <input type="text" v-model="value" />
      <button @click="add">添加</button>
      <ul>
        <li v-for="(item, index) in list" :key="index">
          {{ item }} - <button @click="remove(index)">删除</button>
        </li>
      </ul>
    </div>

    <script src="../vue3.js"></script>
    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {
            count: 1, // 1
            list: [], // 2
            value: "", // 2
          };
        },
        methods: {
          fn(n) {
            // 1
            this.count += n;
          },
          add() {
            // 2
            if (this.value) {
              this.list.push(this.value);
              this.value = "";
            }
          },
          remove(i) {
            // 2
            this.list = this.list.filter((item, index) => index !== i);
          },
        },
        computed: {
          doubleCount() {
            // 1
            return this.count * 2;
          },
        },
        mounted() {
          // 2
          this.list = ["张三", "里斯", "王五"];
        },
      }).mount("#app");
    </script>
  </body>
</html>
